package com.weeego.web.action;

import com.sql.weeego.bean.base.CenterConfig;
import com.sql.weeego.bean.base.CenterNews;
import com.sql.weeego.bean.base.CenterNewsType;
import com.weeego.web.base.BaseAction;
import com.weeego.web.base.Page;
import com.weeego.web.service.CenterNewsService;

import java.util.Date;
import java.util.HashMap;
import java.util.Map;

public class CenterNewsAction extends BaseAction {

	public CenterNewsAction() {
		super();
		this.objectForm = new CenterNews();
	}

	Map msg = new HashMap();
	private String ids;

	@Override
	public String save() {
		try {
			((CenterNews) (this.objectForm)).setAddtime(new Date());
			this.service.saveOrUpdate(objectForm);
			this.commondResult = getText("center.news.save.ok");
			return SUCCESS;
		} catch (Exception ex) {
			return ERROR;
		}
	}

	@Override
	public String action() {
		logger.info(this.getAct() + "act-------------" + objectForm);
		if (this.getAct() == 1) {
			return "add" + save();
		} else if (this.getAct() == 2) {
			if ("".equals(ids)) {
			} else {
				this.commondResult = getText("admin.news.del.ok");
				this.service.deleteById(new CenterNews(), ids);
			}
			return "delsuccess";
		} else if (this.getAct() == 6) {
			logger.info(this.getAct() + "id-------------" + id);
			if (this.id > 0) {
				logger.info(this.getAct() + "edit-------------" + objectForm);
				this.objectForm = this.service.findObjectById(new CenterNews(),
						id);

				return "editread" + SUCCESS;
			} else {
				return "editread" + ERROR;
			}

		} else if (this.getAct() == 7) {
			this.hql = "from CenterNews t order by t.id desc";
			pagesize = 12;
			page = findPage(hql, getNowpage(), getPagesize());
			return "list";
		} else {
			return SUCCESS;
		}
	}

	public Map getMsg() {
		return msg;
	}

	public void setMsg(Map msg) {
		this.msg = msg;
	}

	public String getIds() {
		return ids;
	}

	public void setIds(String ids) {
		this.ids = ids;
	}

}
